#include "systemsettingwidget.h"
#include "ui_systemsettingwidget.h"
#include <QSqlQuery>
#include <QSqlError>
#include <QDebug>
#include <QMessageBox>

SystemSettingWidget::SystemSettingWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SystemSettingWidget)
{
    ui->setupUi(this);
    initWidget();
}

SystemSettingWidget::~SystemSettingWidget()
{
    delete ui;
}

/**
 * @brief 初始化窗体
 */
void SystemSettingWidget::initWidget()
{
    this->setWindowTitle("系统设置");
}

/**
 * @brief 系统初始化
 */
void SystemSettingWidget::on_btn_init_clicked()
{
    QSqlQuery query;
    query.prepare("DELETE FROM attendance");
    query.exec();
    query.prepare("DELETE FROM leave_record");
    query.exec();
    query.prepare("DELETE FROM parking");
    query.exec();
    query.prepare("DELETE FROM parking_apply");
    query.exec();
    query.prepare("DELETE FROM pay_record");
    query.exec();
    query.prepare("DELETE FROM price_mange");
    query.exec();
    query.prepare("DELETE FROM repair_apply");
    query.exec();
    query.prepare("DELETE FROM user");
    query.exec();
    query.prepare("INSERT INTO user (username, passwd, role) VALUES('admin', 'admin', 1)");
    query.exec();
    QMessageBox::information(this, tr("提示"), tr("初始化成功"), QMessageBox::Ok);
}
